package com.project.controller;

import com.project.pojo.Workers;
import com.project.service.WorkerServiceImpl;
import javafx.concurrent.Worker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("worker")
public class WorkerController {
    @Autowired
    @Qualifier("WorkerServiceImpl")
    private WorkerServiceImpl workerService;

    @RequestMapping("/allWorker")
        public String lists(Model model){
            List<Worker> workers = workerService.queryAllWorker();
            System.out.println(workers);
            model.addAttribute("workers", workers);
            return "allWorker";
        }
    @RequestMapping("/toAddWorker")
    public String toAddPaper() {
        return "addWorker";
    }
        @RequestMapping("/addWorker")
    public String addWorker(Workers worker){
            workerService.addWorker(worker);
            return "redirect:/worker/allWorker";
    }
    @RequestMapping("/deleteByName/{workerName}")
    public String deleteBook(@PathVariable("workerName") String name) {
        workerService.deleteByName(name);
        return "redirect:/worker/allWorker";
    }
}
